package com.wangrui.client.form;


import com.google.gwt.core.client.GWT;
import com.google.gwt.user.client.ui.FlowPanel;
import com.google.gwt.user.client.ui.RootPanel;
import com.smartgwt.client.widgets.Window;
import com.wangrui.client.I18nConstants;

import gwtupload.client.IUploader;
import gwtupload.client.IUploader.UploadedInfo;
import gwtupload.client.MultiUploader;
import gwtupload.client.PreloadedImage;
import gwtupload.client.IUploadStatus.Status;
import gwtupload.client.PreloadedImage.OnLoadPreloadedImageHandler;


public class Up  extends Window{

	private FlowPanel panelImages = new FlowPanel();
    I18nConstants c = GWT.create(I18nConstants.class);

	public Up() {
		
		
		setWidth(400);
		setHeight(300);

		MultiUploader defaultUploader = new MultiUploader();

		defaultUploader.addOnFinishUploadHandler(onFinishUploaderHandler);
		addItem(panelImages);

		addItem(defaultUploader);
		
		defaultUploader.setI18Constants(c);
		    // Enable/disable the component
		defaultUploader.setEnabled(true);
		    
		    // Add a finish handler which will load the image once the upload finishes
		defaultUploader.addOnFinishUploadHandler(onFinishUploaderHandler);
	}

	private IUploader.OnFinishUploaderHandler onFinishUploaderHandler = new IUploader.OnFinishUploaderHandler() {
		public void onFinish(IUploader uploader) {
			if (uploader.getStatus() == Status.SUCCESS) {
				new PreloadedImage(uploader.fileUrl(), showImage);
				// The server sends useful information to the client by default
				UploadedInfo info = uploader.getServerInfo();
				System.out.println("File name " + info.name);
				System.out.println("File content-type " + info.ctype);
				System.out.println("File size " + info.size);
				// You can send any customized message and parse it
				System.out.println("Server message " + info.message);
				System.out.println("文件路径"+info.field);
			}
		}
	};

	private OnLoadPreloadedImageHandler showImage = new OnLoadPreloadedImageHandler() {
		public void onLoad(PreloadedImage image) {
			image.setWidth("75px");
			panelImages.add(image);
		}
	};

}
